aboutsummaryrefslogtreecommitdiff
path: root/pages/anime/[...id].js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-04-17 16:17:45 +0700
committerFactiven <[email protected]>2023-04-17 16:17:45 +0700
commit9a9e892a1f43a61188cfd08ef1faaf5100d0a41a (patch)
tree005b6b4e5b786139b266847b6548770f9de6bca3 /pages/anime/[...id].js
parentUpdate [user].js (diff)
downloadmoopa-9a9e892a1f43a61188cfd08ef1faaf5100d0a41a.tar.xz
moopa-9a9e892a1f43a61188cfd08ef1faaf5100d0a41a.zip
4th fixes
Diffstat (limited to 'pages/anime/[...id].js')
-rw-r--r--pages/anime/[...id].js129
1 files changed, 70 insertions, 59 deletions
diff --git a/pages/anime/[...id].js b/pages/anime/[...id].js
index 1df8ea4..8fba4fb 100644
--- a/pages/anime/[...id].js
+++ b/pages/anime/[...id].js
@@ -73,25 +73,6 @@ export default function Himitsu({
episodeIndo = episode;
}
- async function handleUpdate(data) {
- if (!sessions) return;
- const res = await fetch("/api/update-user", {
- method: "POST",
- body: JSON.stringify({
- name: sessions?.user.name,
- newData: {
- recentWatch: data,
- },
- }),
- headers: {
- "Content-Type": "application/json",
- },
- });
- console.log(res.status);
- }
-
- // console.log(lastPlayed);
-
return (
<>
<Head>
@@ -158,24 +139,7 @@ export default function Himitsu({
</div>
<div className="flex">
{epi1 && epi1[0] ? (
- <Link
- href={`/anime/watch/${epi1[0].id}/${info.id}`}
- onClick={() =>
- handleUpdate({
- title: {
- romaji:
- info.title.romaji ||
- info.title.english ||
- info.title.native,
- },
- description: info.description,
- coverImage: {
- extraLarge: info.image,
- },
- id: parseInt(info.id),
- })
- }
- >
+ <Link href={`/anime/watch/${epi1[0].id}/${info.id}`}>
<h1 className="flex cursor-pointer items-center gap-2 rounded-[20px] bg-[#ff9537] px-4 py-2 font-bold text-[#ffffff]">
<svg
xmlns="http://www.w3.org/2000/svg"
@@ -415,21 +379,6 @@ export default function Himitsu({
return (
<div key={index} className="flex flex-col gap-3 px-2">
<Link
- onClick={() =>
- handleUpdate({
- title: {
- romaji:
- info.title.romaji ||
- info.title.english ||
- info.title.native,
- },
- description: info.description,
- coverImage: {
- extraLarge: info.image,
- },
- id: parseInt(info.id),
- })
- }
href={`/anime/watch/${episode.id}/${info.id}/${
item ? `${item.time}` : ""
}`}
@@ -615,18 +564,80 @@ export async function getServerSideProps(context) {
let lastPlayed = null;
if (session) {
- const res = await fetch(
- `https://moopa-anilist.vercel.app/api/get-media?username=${query.user}`
- );
+ const response = await fetch("https://graphql.anilist.co/", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ query: `
+ query ($username: String, $status: MediaListStatus) {
+ MediaListCollection(userName: $username, type: ANIME, status: $status, sort: SCORE_DESC) {
+ user {
+ id
+ name
+ about (asHtml: true)
+ createdAt
+ avatar {
+ large
+ }
+ statistics {
+ anime {
+ count
+ episodesWatched
+ meanScore
+ minutesWatched
+ }
+ }
+ bannerImage
+ mediaListOptions {
+ animeList {
+ sectionOrder
+ }
+ }
+ }
+ lists {
+ status
+ name
+ entries {
+ id
+ mediaId
+ status
+ progress
+ score
+ media {
+ id
+ status
+ title {
+ english
+ romaji
+ }
+ episodes
+ coverImage {
+ large
+ }
+ }
+ }
+ }
+ }
+ }
+ `,
+ variables: {
+ username: session?.user.name,
+ },
+ }),
+ });
+
+ const dat = await response.json();
- const resp = await fetch(`/api/get-user?userName=${session?.user.name}`);
- const data = await resp.json();
+ // const resp = await fetch(`/api/get-user?userName=${session?.user.name}`);
+ // const data = await resp.json();
- lastPlayed = data?.recentWatch.filter(
+ lastPlayed = session?.user?.recentWatch?.filter(
(item) => item.title.romaji === info.title.romaji
)[0]?.episode;
- const prog = await res.json();
+ const prog = dat.data.MediaListCollection;
const gat = prog.lists.map((item) => item.entries);
const git = gat.map((item) =>